// JQSqlBaseIF
class JQRecordDailyBatis extends global.JQSqlBaseIF {
	
	async query(params,first,size,is_count){	
		if(!this.conn)console.log('do_action::conn error');
		// let wheres=[];
		let values=[params.visitor_id,params.date,params.date];
		let sql = `
		   select date_format(time,'%H:%i:%s')  time,  amount,obj from
		   (select time,amount, obj from 
		      cb_record where visitor_id=? and 
		      time >= STR_TO_DATE(?, '%Y-%m-%d')
		      and time < STR_TO_DATE(?, '%Y-%m-%d')  + interval 1 day     order by time) t
		`
		let result = await this.conn.readDB(sql,values);
		return result;
			
	}
	
	async days(){	
			if(!this.conn)console.log('do_action::conn error');
			
			let sql = `
			  SELECT  DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL n DAY),'%m-%d') 
			   AS quantum, to_days(DATE_SUB(CURDATE(), INTERVAL n DAY)) as  days
			  FROM (SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4)
			   AS day_data order by quantum 
			`
			let result = await this.conn.readDB(sql);
			return result;
				
		}
		
		
		
		
		async months(){	
			if(!this.conn)console.log('do_action::conn error');
			
			let sql = `
				SELECT   DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL n month),'%y-%m') as  quantum,
				 DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL n month),'%y-%m') as  months
				 FROM (SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4)
				 AS day_data order by quantum  
			`
			let result = await this.conn.readDB(sql);
			return result;
		}
		
		async weeks(){	
				if(!this.conn)console.log('do_action::conn error');
				
				let sql = `
					SELECT   DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL n week),'%y-%V') as  quantum,
					DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL n week),'%y-%V') as  weeks
					FROM (SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4)
					AS day_data order by quantum 
				`
				let result = await this.conn.readDB(sql);
				return result;
		}
		
		async years(){	
			if(!this.conn)console.log('do_action::conn error');
			
			let sql = `
			    SELECT   year(DATE_SUB(CURDATE(), INTERVAL n year))  
			    AS quantum, year(DATE_SUB(CURDATE(), INTERVAL n year)) as  years
			    FROM (SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4)
			    AS day_data order by quantum   
			`
			let result = await this.conn.readDB(sql);
			return result;
		}

}
module.exports = JQRecordDailyBatis;


